package ui;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;

public class CheckButton extends JButton{
	private static final long serialVersionUID = 1L;
	ImageIcon checkYes = new ImageIcon("./src/ui/images/checkBoxButtonEmptyChecked_22x22.png");
	ImageIcon checkNo = new ImageIcon("./src/ui/images/checkBoxButtonEmpty_22x22.png");
	private boolean selected;
	private boolean opaquesetting;
	

	public CheckButton() {
		
	}
	
	public CheckButton(String text) {
		setText(text);
	}
	
	public CheckButton(String normalImagePath,String checkedImagePath) {
		checkYes = new ImageIcon(checkedImagePath);
		checkNo = new ImageIcon(normalImagePath);
		super.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				setSelected(!isSelected());
			}
		});
		opaquesetting=true;
	}
	
	public void setSelected(boolean selected) {
		this.selected=selected;
		if (selected) {
			super.setIcon(checkYes);
			if(opaquesetting) super.setBackground(new Color(230,230,230));
		}else{
			super.setIcon(checkNo);		
			if(opaquesetting) super.setBackground(null);
		}
		revalidate();
		repaint();
	}
	
	public boolean isSelected() {
		return selected;
	}
	
	public void setOpaqueIfSelected(boolean b){
		this.opaquesetting=b;
	}

}
